import { NestFactory } from '@nestjs/core';
import { VersioningType } from '@nestjs/common'
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express' 
import { join } from 'path'
//import { Response } from './common/response'
import * as cors from 'cors'
import * as session from 'express-session'

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  //静态资源访问（从该目录查找→ E:\newking\Nest.js\demo\dist\images）
  app.useStaticAssets(join(__dirname,'images'),{
    prefix:'/newking'
  })  
  //cors允许跨域
  app.use(cors())
  //app.enableCors()
  //开启api版本设置
  app.enableVersioning({
    type: VersioningType.URI
  })
  //设置session时，往前端植入
  app.use(session({ secret: "newking", rolling: true, name: "newsId", cookie: { maxAge: 999999 } }))
  
  //响应拦截器 路由程序前执行
  //app.useGlobalInterceptors(new Response())

  await app.listen(3000);
}
bootstrap();
